package com.panshi.admin_manage.controller;

import com.panshi.admin_manage.service.IFunctionService;
import com.panshi.vo.DataResult;
import com.panshi.vo.SysFunction;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@CrossOrigin
public class FuncController {

    @Autowired

    private IFunctionService functionService;

    @GetMapping("/func-app/list")
    public DataResult find(){
        DataResult dataResult = new DataResult();
        dataResult.setData(functionService.list(null));
        return dataResult;
    }

    @PostMapping("/func-app/add")
    public Boolean add(@RequestBody SysFunction function){
        return functionService.save(function);
    }

    @GetMapping("/func-app/del/{id}")
    public Boolean del(@PathVariable Integer id){
        SysFunction function = new SysFunction();
        function.setId(id);
        function.setFStatus(-1);
        return functionService.save(function);
    }

    @GetMapping("/func-app/byid/{id}")
    public DataResult fidnfuncById(@PathVariable Integer id){
        DataResult dataResult = new DataResult();
        dataResult.setData(functionService.getById(id));
        return dataResult;
    }

    @PostMapping("/func-app/upd")
    public Boolean upd(@RequestBody SysFunction function){
        return functionService.updateById(function);
    }

}
